﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body class="easyui-layout">
   
    <link href="../hcjsui/jquery-easyui-1.3.3/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../hcjsui/jquery-easyui-1.3.3/themes/icon.css" rel="stylesheet" type="text/css" />
 
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="../hcjsui/jquery-easyui-1.3.3/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../hcjsui/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js" charset="utf-8" type="text/javascript"></script>
    <script src="../hcjsui/Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="../hcjsui/js/json2.js" type="text/javascript"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script src="../hcjsui/js/customer.js" type="text/javascript"></script>
    <script type="text/javascript" src="../hcjsui/js/usbocx.js"></script>
    <script src="../hcjsui/Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../hcjsui/js/easyui-extend/form.js" type="text/javascript"></script>
    <script src="../hcjsui/js/easyui-extend/window.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hc.js"></script>
    <div region="north" title="" split="false" border="false" style="height: 60px;">
        <table width="90%">
            <tr>
                <td class="auto-style1">
                    <form id="searchForm" method="post" runat="server">
                        <div>
                            类型：
                                <select id="nofindtype" name="nofindtype" class="easyui-combobox" style="width: 150px;" disabled="disabled">
                                    <option value="机构">机构</option>
                                    <option value="银行">银行</option>
                                </select>
                            单位名称：<input id="findBranchID" name="findBranchID" />
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                  <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-up'" onclick="javascript:selok();">确定</a>

                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:selno();;">返回</a>

                        </div>
                    </form>
                </td>


            </tr>
            <tr>
                <td></td>
            </tr>
        </table>

    </div>
    <div region="center" style="padding: 0px;" border="false">

        <table id="ui_department_tg"></table>
    </div>



    <script type="text/javascript">

        spsetBaseNoBt("mrDepartment", "DepID", "mrDepartment as T", "*", "#ui_department_tg", "mrdep");
        var Mbranchobj;//机构对象
        var Mbankobj;
        //$(document).ready(function () {
        //    if (window.screen) {
        //        var myw = screen.availWidth ;
        //        var myh = screen.availHeight;
        //        window.moveTo(0, 0);
        //        window.resizeTo(myw, myh);
        //    }
        //});
        $(function () {
            var showtype = getUrlParam("showtype");
            if (showtype == 0) {
                $("#nofindtype").combobox("select", "机构");
            }
            else if (showtype == 1) {
                $("#nofindtype").combobox("select", "银行");
            }
            else {
                $.messager.alert("提示信息", "没定义的参数！");
                return;
            }



            $('#nofindtype').combobox({
                onChange: function (newValue, oldValue) {
                    if (newValue == "机构") {
                        $("#findBranchID").combobox("loadData", Mbranchobj);

                    }
                    else {
                        $("#findBranchID").combobox("loadData", Mbankobj);
                    }
                }
            });
            //这里data: datebranch  无法加载数据
            var datebranch = spGetJson(sposelUrlByFNoState("BranchID,BranchName", "mrBranch", "type in('本部','分部')", "", "", "BranchID"));
            Mbranchobj = $.parseJSON(datebranch);
            datebranch = spGetJson(sposelUrlByFNoState("BranchID,BranchName", "mrBranch", "type in('银行','分行','一级支行')", "", "", "BranchID"));
            Mbankobj = $.parseJSON(datebranch);

            $('#fBranchID').combobox({
                editable: false,
                valueField: 'BranchID',
                textField: 'BranchName',
                multiple: false,
                // data: datebranch,
                onChange: function (newValue, oldValue) {
                    runloadselecttree(newValue);
                },
                onLoadSuccess: function () { //加载完成后,设置选中第一项
                    var val = $(this).combobox("getData");
                    for (var item in val[0]) {
                        if (item == "BranchID") {
                            $(this).combobox("select", val[0][item]);
                        }
                    }
                }
            });
            $('#findBranchID').combobox({
                editable: false,
                valueField: 'BranchID',
                textField: 'BranchName',
                multiple: false,
                onChange: function (newValue, oldValue) {
                    Search();
                },
                onLoadSuccess: function () {
                    var val = $(this).combobox("getData");
                    for (var item in val[0]) {
                        if (item == "BranchID") {
                            $(this).combobox("select", val[0][item]);
                        }
                    }
                }
            });
            if (showtype == 0) {
                $("#findBranchID").combobox("loadData", Mbranchobj);
            }
            else if (showtype == 1) {
                $("#findBranchID").combobox("loadData", Mbankobj);
            }
            BindGrid();
        });
        var oldSelectDepartmentId;   //上次点选的DepartmentId

        function BindGrid() {


            $(grid1ID).treegrid({       //初始化treegrid
                url: urltree,
                idField: 'id',
                treeField: 'text',
                rownumbers: true,
                loadFilter: myLoadFilter,
                // fit:true,
                fitColumns: true, //是否自适应宽度
                fit: true, //是否自适应父容器的大小
                columns: [[

                            //{ field: 'text', title: '名称', width: 250 },
                             {
                                 title: '名称', field: 'text', formatter: function (value, row, rowIndex) {
                                     if (row.ShowInfo2 == "人员") {
                                         return "<input type='checkbox'     id='checkuser_" + row.id + "' />" + row.text;
                                     }
                                     else { return row.text; }
                                 }, width: 200
                             },
                            { field: 'ShowInfo2', title: '类型', width: 250 },

                {
                    field: "y", title: "操作", width: 50, align: "center", formatter: function (value, row, index) {
                        if (row.ShowInfo2 == "人员")
                            return "<a href='#' style='color: #369591;' onclick='javascript:Update(" + row.id + ")'>选择</a>";
                    }
                }

                ]],
                onClickRow: function (row) {

                },
                queryParams: $("#searchForm").formToJson()
            });



        }

        function myLoadFilter(data, parentId) {
            function setData() {
                var todo = [];
                for (var i = 0; i < data.length; i++) {
                    todo.push(data[i]);
                }
                while (todo.length) {
                    var node = todo.shift();
                    if (node.children) {
                        node.state = 'closed';
                        node.children1 = node.children;
                        node.children = undefined;
                        todo = todo.concat(node.children1);
                    }
                }
            }

            setData(data);
            var tg = $(this);
            var opts = tg.treegrid('options');
            opts.onBeforeExpand = function (row) {
                if (row.children1) {
                    tg.treegrid('append', {
                        parent: row[opts.idField],
                        data: row.children1
                    });
                    row.children1 = undefined;
                    tg.treegrid('expand', row[opts.idField]);
                }
                return row.children1 == undefined;
            };
            return data;
        }

        var departmentIds = "";

        function ui_department_expandall() {
            $("#ui_department_tg").treegrid("expandAll");
        }
        function ui_department_collapseall() {
            $("#ui_department_tg").treegrid("collapseAll");
        }
        function runloadselecttree(id) {
            $('#fParentId').combotree({
                url: urltree + '&wheresp= and T.BranchID=' + id
            });
        }

        var urltree = "../ashx/sp.ashx?action=seltree&tableinfo= View_Dep_User as T  &refields= ID,ShowInfo,ShowInfo2,ParentId,iconCls ";
        function Search() {
            //为什么 reload不带参数过去？
            // $(grid1ID).treegrid("options").queryParams = $("#searchForm").formToJson();
            $.ajax({
                type: "POST",
                url: urltree,
                data: $("#searchForm").formToJson(),
                success: function (Data) {
                    $(grid1ID).treegrid("loadData", eval(Data));
                }
            });
        }



        function selok() {
            var idList = "";
            $("input:checked").each(function () {
                var id = $(this).attr("id");
                if (id.indexOf('check_type') == -1 && id.indexOf("checkuser_") > -1)
                    idList += id.replace("checkuser_", '') + ',';
            });
            if (idList.length > 1) {
                idList = idList.substring(0, idList.length - 1);
            }
            if (idList.length == 0) {
                $.messager.alert("提示信息", "请选择！");
            } else {
                //alert(idList);
                window.closeArgs.haschange = true;
                window.closeArgs.data = idList;
                window.parent.$.closeWindow("hcshowtablesel");
            }


        }
        function selno() {


            if (window.parent != window) {
                window.parent.$.closeWindow("hcshowtablesel");
            } else {
                window.close();
            }



        }


    </script>
</body>
</html>
